package com.service.product.impl;

import com.action.pc.order.OrderProductVo;
import com.bean.*;
import com.dao.Order_productMapper;
import com.dao.ProductMapper;
import com.dao.Product_special_relMapper;
import com.dao.Wx_userMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.core.AbstractService;
import com.service.product.ProductService;
import com.service.wxuser.WxUserService;
import com.util.StringUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/10.
 */
@Service
public class ProductServiceImpl extends AbstractService<Product, Integer> implements ProductService {
    Logger logger = Logger.getLogger(ProductServiceImpl.class);

    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private Order_productMapper order_productMapper;
    @Autowired
    private Product_special_relMapper product_special_relMapper;


    @Override
    public List<Product> getDraList(Integer cityId) {
        return productMapper.selectDraList(cityId);
    }

    @Override
    public List<Product> getRecommendList(Integer cityId) {
        return productMapper.getRecommendList(cityId);
    }

    @Override
    public List<Map> getDraListByMerchantId(Integer MerchantId) {
        return productMapper.selectDraListByMerchantId(MerchantId);
    }

    @Override
    public List<Map> getRecommendListByMerchantId(Integer MerchantId) {
        return productMapper.getRecommendListByMerchantId(MerchantId);
    }


    @Override
    public Page findByPage(int pageNum, int pageSize, HashMap<String, Object> paraMap) {
        PageHelper.startPage(pageNum, pageSize);
        Page page = (Page) productMapper.findAll(paraMap);
        return page;
    }

    @Override
    public int saveProduct(Product product) {
        if (product != null) {
            if (product.getId() != null) {
                productMapper.updateByPrimaryKeySelective(product);
            } else {
                productMapper.insertSelective(product);
            }
            return product.getId();
        }
        return -1;
    }

    @Override
    public List<Product_special_rel> findByProductId(Integer id) {
        if (id != null) {
            List<Product_special_rel> list = product_special_relMapper.findByProductId(id);
            return list;
        }
        return null;
    }

    @Override
    public void updateByProductId(Integer id, List<Product_special_rel> list) {
        if (id != null) product_special_relMapper.deleteByProductId(id);
        if (list != null) for (Product_special_rel p : list) {
            product_special_relMapper.insert(p);
        }
    }

    @Override
    public void updatePSRById(Product_special_rel p) {
        product_special_relMapper.updateByPrimaryKeySelective(p);
    }


}